﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;

namespace Web_HengliSeed.Sys_Manage
{
    public partial class M_EditWebLink : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ClassFile.Function.CheckState();
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            string strClassID = Common.GetMes.GetRequestQuery(Request, "CID");
            if (!string.IsNullOrEmpty(strClassID))
            {
                OleDbDataReader DataRead = BLL.WebLink.GetClassMes(strClassID);
                if (DataRead.HasRows)
                {
                    DataRead.Read();
                    txtWebLinkTitle.Value = Server.HtmlDecode(DataRead["T_WebLinkTitle"].ToString());
                    txtWebLinkImage.Value = Server.HtmlDecode(DataRead["T_WebLinkImage"].ToString());
                    txtWebLinkUrl.Value = Server.HtmlDecode(DataRead["T_WebLinkUrl"].ToString());
                }
                DataRead.Close();
                DataRead.Dispose();
            }
        }
        protected void BtnSave_Click(object sender, EventArgs e)
        {
            string strClassID = Common.GetMes.GetRequestQuery(Request, "CID");
            string strClassName = Server.HtmlEncode(txtWebLinkTitle.Value.Trim());
            if (string.IsNullOrEmpty(strClassID))
            {
                if (BLL.WebLink.EditClassMes(strClassName, Server.HtmlEncode(txtWebLinkImage.Value.Trim()), Server.HtmlEncode(txtWebLinkUrl.Value.Trim())))
                {
                    Common.ShowMessage.myScriptMes(Page, "Suess", "if(confirm(\"信息保存成功，是否继续添加？否则返回信息列表。\")) {location.href=\"M_EditWebLink.aspx\"} else  {location.href=\"M_WebLinkInfo.aspx\"} ");
                }
                else
                {
                    Common.ShowMessage.Show(Page, "error", "信息保存失败，请重试或联系技术人员......");
                }
            }
            else
            {
                if (BLL.WebLink.EditClassMes(strClassID, strClassName, Server.HtmlEncode(txtWebLinkImage.Value.Trim()), Server.HtmlEncode(txtWebLinkUrl.Value.Trim())))
                {
                    Common.ShowMessage.Show(Page, "suess", "信息保存成功......", "M_ProductClass.aspx");
                }
                else
                {
                    Common.ShowMessage.Show(Page, "error", "信息保存失败，请重试或联系技术人员......");
                }
            }
        }
    }
}
